<?php
namespace app\admin\controller;
use app\admin\model\Company as CompanyModel;
use app\admin\controller\Common;
class Company extends Common
{

    public function lst()
    {   $auth=new Auth();
        $company=new CompanyModel();
        
        $companys=$company->order('sort desc')->paginate(10);
        $this->assign('companys',$companys);
        return view();
	}


	    public function add(){
        if(request()->isPost()){
            $data=input('post.');
            $data['sort']=0;
            //print_r($data);
            $validate = \think\Loader::validate('Company');
            if(!$validate->scene('add')->check($data)){
                $this->error($validate->getError());
            }
            $company=new CompanyModel;
            if($company->save($data)){
                $this->success('添加厂家成功',url('lst'));
            }else{
                $this->error('添加厂家失败！');
            }
        }
       
        return view();
    }

    public function edit(){
        if(request()->isPost()){
            $data=input('post.');
            //print_r($data);
            $validate = \think\Loader::validate('Company');
            if(!$validate->scene('edit')->check($data)){
                $this->error($validate->getError());
            }
            $company=new CompanyModel;
            $save=$company->update($data);
            if($save){
                $this->success('修改厂家成功！',url('lst'));
            }else{
                $this->error('修改厂家失败！');
            }
            return;
        }
        $company=CompanyModel::find(input('id'));
        $this->assign('company',$company);
      
        return view();
    }

    public function del(){
        $del=CompanyModel::destroy(input('id'));
        if($del){
           $this->success('删除厂家成功！',url('lst')); 
        }else{
            $this->error('删除厂家失败！');
        }
    }

    

}
